
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<body>
     <button>按钮</button>
    <script>
       var that;
        class Star {
             
            constructor(name,age){
                that=this;
                this.name=name;/* this指创建出来的实例化对象 （25行的zs）*/
                this.age=age;
                this.btn=document.querySelector("button");
                this.btn.onclick=this.sing;/* btn调用了sing，那么这里的this是btn *//* sing不加（），加了就立刻运行了，而不是点击后运行 */
            }   
            sing(){
                console.log(that.name);
            }
        }
        var zs=new Star("张三",18);
        var ls=new Star("李四",20);
        console.log(zs);
        console.log(ls); 
        ls.sing();

    </script>
</body>
</html>